<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>BFC 清除浮动</title>
    <style>
        .container {
            margin-top: 30px;
            width: 400px;
            height: 400px;
            background-color: red;
        }
        .container::before {
            content: " ";
            display: table;
        }
        .col{
            margin-top: 20px;
            width: 100px;
            height: 100px;
            /* float: left; */ /* 如果是设了float: left，形成了BFC，就不会发生垂直方向外边距合并。大概是这样吧。 */
        }
        .col1 {
            background-color: blue;
        }
        .col2 {
            background-color: green;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="col col1"></div>
        <div class="col col2"></div>
    </div>
</body>
</html>